using System;
using System.Collections.Generic;
using System.Text;
using log4net;

namespace Sedna.Core.Scheduler.Conditions
{
    public abstract class BaseCondition : ICondition
    {
        private ILog log = LogManager.GetLogger(typeof(BaseCondition));

        private bool enabled;

        public event EventHandler Trigger;

        public virtual bool Enabled
        {
            get { return enabled; }
            set
            {
                enabled = value;
                
                if (enabled)
                {
                    OnEnable();
                }
                else
                {
                    OnDisable();
                }
            }
        }

        protected virtual void OnTrigger()
        {
            if (Trigger != null)
            {
                try
                {
                    Trigger(this, EventArgs.Empty);
                }
                catch (Exception e)
                {
                    log.Error(e);
                }
            }
        }

        protected virtual void OnEnable()
        {
        }

        protected virtual void OnDisable()
        {
        }
    }
}
